package com.studyroom.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;

import org.springframework.amqp.core.BindingBuilder;
import org.springframework.context.annotation.Configuration;

import static com.studyroom.utils.RabbitMqContants.*;

@Configuration
public class RabbitMqConfig {
    //声明交换机
    @Bean
    public Exchange ExchangeTopic(){
        return new TopicExchange (EXCHANGE_TOPIC);
    }

    //声明队列 一对一聊天
    @Bean
    public Queue chatSoloQueueTopic(){
        return new Queue (CHAT_SOLO_QUEUE_TOPIC);
    }
    //声明队列  邮件
    @Bean
    public Queue mailQueueTopic(){
        return new Queue (MAIL_QUEUE_TOPIC);
    }


    //绑定交换和一对一聊天队列
    @Bean
    public Binding chatSoloBinding(){
        return BindingBuilder.bind (chatSoloQueueTopic ()).to (ExchangeTopic ()).with ("chat.solo").noargs ();
    }
    //绑定 邮件队列
    @Bean
    public Binding mailBinding(){
        return BindingBuilder.bind (mailQueueTopic ()).to (ExchangeTopic ()).with ("mail").noargs ();
    }
}
